// component/goodsList/goodsList.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    param: {
      type: Object
    },
    template: {
      type: Object
    },
    api_host: {
      type: String
    },
    wxapp_img: {
      type: Object
    },
    is_member_price: {
      type: Number
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    systemInfo: getApp().core.getSystemInfoSync(),
    top: 0,
    pitch: 0,
    scroll: "demo0",
    leftheight: 0,
    left_list: [],
    right_list: []
  },
  lifetimes: {
    attached: function () {
      var top = 0
      var statusBarHeight = this.px2rpx(this.data.systemInfo.statusBarHeight)
      if (this.data.template[0].type == 'shop_info') {
        var shop_info_height = statusBarHeight + 85
        top += shop_info_height
      }
      if (this.data.template[1].type == 'search') {
        top += 78
      }

      if (this.data.template[0].type != 'shop_info') {
        top = (statusBarHeight + 88)
      }
      
      this.setData({
        top: top
      })
      this.readData()
    },
  },

  methods: {
    onGoods: function (e) {
      var id = e.currentTarget.dataset.id
      wx.navigateTo({
        url: '/pages/goods/goods?id=' + id,
      })
    },
    px2rpx: function (px) {
      const screenWidth = this.data.systemInfo.screenWidth
      return (750 / screenWidth) * px
    },
    clicktab(e) {
      this.setData({
        pitch: e.currentTarget.dataset.index,
        scroll: 'demo' + (e.currentTarget.dataset.index - 1)
      })
      this.readData()
    },
    readData: function () {
      var left_list1 = []
      var right_list1 = []
      for (var i = 0; i < this.data.param.list[this.data.pitch].goods_list.length; i++) {
        if (i % 2 == 0) {
          left_list1.push(this.data.param.list[this.data.pitch].goods_list[i])
        } else {
          right_list1.push(this.data.param.list[this.data.pitch].goods_list[i])
        }
      }
      this.setData({
        left_list: left_list1,
        right_list: right_list1
      })
    }
  }
})